Skip to content

use JSON for ajax#412

Merged
simonLeary42 merged 8 commits intomainfrom
ajax-json
Dec 18, 2025
Merged

use JSON for ajax#412
simonLeary42 merged 8 commits intomainfrom
ajax-json

Conversation

@simonLeary42
Copy link
Member

@simonLeary42 simonLeary42 commented Dec 18, 2025

closes #330

Screen.Recording.2025-12-18.at.10.14.52.AM.2.mov

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes AJAX endpoints by migrating from plain text/HTML responses to structured JSON responses, improving API consistency and making client-side data handling more robust.

  • Refactored SSH key generation and validation endpoints to return JSON instead of HTML-wrapped text
  • Updated page content retrieval endpoint to return JSON instead of plain text
  • Modified all corresponding JavaScript AJAX calls to expect and parse JSON responses with proper dataType specification

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
webroot/panel/modal/new_key.php Updated JavaScript to parse JSON responses for SSH key generation and validation, accessing structured fields instead of parsing HTML sections
webroot/js/ajax/ssh_validate.php Converted endpoint to return JSON with is_valid field and proper Content-Type header
webroot/js/ajax/ssh_generate.php Converted endpoint to return JSON with public and private fields, removed HTML section wrappers
webroot/admin/content.php Updated JavaScript to parse JSON response and extract content field from structured response
webroot/admin/ajax/get_page_contents.php Converted endpoint to return JSON with content field and proper Content-Type header
Comments suppressed due to low confidence (1)

webroot/panel/modal/new_key.php:112

  • The AJAX request lacks error handling. If the validation request fails, the UI state may be inconsistent (the button could remain in the wrong state). Consider adding an error callback to handle network failures or server-side errors gracefully.
        $.ajax({
            url: "<?php echo getURL("js/ajax/ssh_validate.php"); ?>",
            dataType: "json",
            type: "POST",
            data: {
                key: key
            },
            success: function(result) {
                if (result.is_valid) {
                    $("input[id=add-key]").prop("disabled", false);
                    $("textarea[name=key]").css("box-shadow", "none");
                } else {
                    $("input[id=add-key]").prop("disabled", true);
                    $("textarea[name=key]").css("box-shadow", "0 0 0 0.3rem rgba(220,53,69,0.25)");
                }
            }
        });

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@simonLeary42 simonLeary42 marked this pull request as ready for review December 18, 2025 15:37
@simonLeary42 simonLeary42 merged commit 1706d1e into main Dec 18, 2025
3 checks passed
@simonLeary42 simonLeary42 deleted the ajax-json branch December 18, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

change all ajax to json

1 participant